home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Introducing the New Way to Shop from Home
/
Iceland.iso
/
pc
/
internetaccess.dir
/
00026_Script_Multi-State Button
< prev
next >
Wrap
Text File
|
2003-03-05
|
12KB
|
417 lines
-- DESCRIPTION --
on getBehaviorDescription me
return \
"MULTISTATE TOGGLE BUTTON" & RETURN & RETURN & \
"This behavior toggles the sprite it is attached to between two states: OFF and ON. " & \
"In each state, the member of the sprite is set according to the position of the mouse (elsewhere, rollover, mouseDown)." & RETURN & \
"The behavior returns the current state of the button in response to a #ToggleButton_State call." & RETURN & RETURN & \
"RADIO BUTTON GROUP" & RETURN & \
"To create a group of radio buttons, give each button in the same group the same ID. " & \
"Switching one button in the group on will switch all others off." & RETURN & RETURN & \
"PERMITTED MEMBER TYPES" & RETURN & \
"Graphic" & RETURN & RETURN & \
"PARAMETERS:" & RETURN & \
"-- OFF state --" & RETURN & \
"* Standard member (when mouse is elsewhere)" & RETURN & \
"* Rollover member" & RETURN & \
"* MouseDown member" & RETURN & \
"-- ON state --" & RETURN & \
"* Standard member" & RETURN & \
"* Rollover member" & RETURN & \
"* MouseDown member" & RETURN & \
"-- COMMAND --" & RETURN & \
"* Sent when the button is switched ON" & RETURN & \
"* Sent when the button is switched OFF" & RETURN & \
"-- Optional --" & RETURN & \
"* Toggle group ID (to create a group of radio buttons)" & RETURN & RETURN & \
"If members are placed consecutively in the cast in this order then default values can be used to create the button."
end getBehaviorDescription
on getBehaviorTooltip me
return \
"Create an ON/OFF button which reacts to rollovers and clicks. " & \
"Use several such buttons together as a radio button group."
end getBehaviorTooltip
-- NOTES FOR DEVELOPERS --
--
-- This behavior communicates extensively with other sprites. Since there
-- may be up to 1000 sprites, it is important to use sendAllSprites with
-- prudence. Indeed, this behavior only uses sendAllSprites once, in the
-- Initialize handler.
--
-- ToggleButton_GroupRollCall
-- The purpose of the call is to identify all other members of the radio
-- button group. The behaviors that field the call add their object reference
-- to a list, ourGroupList. Each behavior stores a pointer to this list.
-- Subsequent communications are of the form:
--
-- call (#customMessage, ourGroupList, additionalParameters)
--
-- This limits the messaging process to only those sprites which need to know.
--
-- ToggleButton_MouseDownList
-- Lists can be used to make information available to other sprites without
-- sending any messages. All behaviors in a group also share a pointer to an
-- ourMouseDown list. Whenever the user clicks on one of the members, the
-- unique item in this list is set to TRUE. When the mouse is released, it
-- is set to FALSE. All buttons in the group know instantaneously if any
-- member of the group has been clicked. This means that if the mouse is
-- clicked on one button in the group, other group members will switch to
-- their mouseDown state as the mouse is draggged over them
--
-- ToggleButton_Rollover
-- When the mouse is released, the clickOn sprite asks each other group
-- member in turn if the mouse is currently over it. If none respond, then
-- ourMouseDown is set to [FALSE]. If any buttons respond, then the
-- mouseUp event sent to the topmost button will activate its Toggle handler.
--
-- ToggleButton_Off
-- When a button is toggled on, it instructs all others in the group to switch
-- themselves off.
--
-- ToggleButton_State, ToggleButton_ActiveButton
-- These two calls are not used in the behavior itself. they are included
-- to let you know the state of a particular button, or to know which button
-- in a given group is currently ON.
--
-- If you have only one button, then you can use the ToggleButton_State
-- call with no parameters. If there are several buttons, then you can either
-- send an empty list out to a given group, and receive a list of the state of
-- each button in reply.
--
-- ToggleButton_ActiveButton should be sent to a particular group. You
-- must include an empty property list in your call, and will receive in reply
-- a list of the form: [#sprite: <spriteNum>, #behavior: <object reference>]
--
--
--
-- HISTORY --
--
-- 11 September 1998, written for the D7 Behaviors Palette by James Newton
-- 5 January 2000: updated to D8 <km>
-- PROPERTIES --
property spriteNum
property mySprite
-- author-defined parameters
property myOffMember
property myOffOverMember
property myOffDownMember
property myOffCommand
property myOnMember
property myOnOverMember
property myOnDownMember
property myOnCommand
-- internal properties
property theMouseWasUp
property myRollover
property myState -- TRUE | FALSE: max one button in group TRUE at one time
-- shared properties
property ourID -- string common to all buttons in a group
property ourGroupList -- list of behaviors in the group
property ourMouseDown -- list indicating if the clickOn is in the group
-- EVENT HANDLERS --
on beginSprite me
Initialize me
end beginSprite
on prepareFrame me
CheckForRollover me
end prepareFrame
on mouseDown me
ClickOn me
end mouseDown
on mouseUp me
if ourMouseDown[1] then Toggle me
end mouseUp
on mouseUpOutside me
CheckGroupForClick me
end mouseUpOutside
-- CUSTOM HANDLERS --
on Initialize me -- sent by beginSprite
mySprite = sprite(me.spriteNum)
ourGroupList = []
-- Insurance: properties are indeed #members
myOffMember = member (myOffMember)
myOffOverMember = member (myOffOverMember)
myOffDownMember = member (myOffDownMember)
myOnMember = member (myOnMember)
myOnOverMember = member (myOnOverMember)
myOnDownMember = member (myOnDownMember)
sendAllSprites (#ToggleButton_GroupRollCall, ourID, ourGroupList)
call (#ToggleButton_MouseDownList, ourGroupList, [FALSE])
end Initialize
on CheckForRollover me -- sent by prepareFrame
mouseOverMe = (the rollover = me.spriteNum)
if myRollover = mouseOverMe then
if theMouseWasUp = the mouseUp then
exit -- Nothing has changed
else
theMouseWasUp = the mouseUp
if mouseOverMe then
if the mouseUp then
-- Mouse was clicked elsewhere then dragged and released over button
case myState of
TRUE: mySprite.member = myOnOverMember
FALSE: mySprite.member = myOffOverMember
end case
end if
end if
end if
else
set myRollover to mouseOverMe
if ourMouseDown[1] then
if myRollover then
case myState of
TRUE: mySprite.member = myOnDownMember
FALSE: mySprite.member = myOffDownMember
end case
else
-- Indicate that mouseUpOutside will have no effect
case myState of
TRUE: mySprite.member = myOnMember
FALSE: mySprite.member = myOffMember
end case
end if
else
if not the mouseDown and myRollover then
case myState of
TRUE: mySprite.member = myOnOverMember
FALSE: mySprite.member = myOffOverMember
end case
else
-- No reaction if mouse was clicked elsewhere and dragged to button
case myState of
TRUE: mySprite.member = myOnMember
FALSE: mySprite.member = myOffMember
end case
end if
end if
end if
end CheckForRollover
on ClickOn me -- sent by mouseDown, CheckForRollover
ourMouseDown[1] = TRUE
case myState of
TRUE: mySprite.member = myOnDownMember
FALSE: mySprite.member = myOffDownMember
end case
end ClickOn
on Toggle me, whichState -- sent by mouseUp, ToggleButton_Off
if voidP (whichState) then
myState = not myState
else
myState = whichState
end if
ourMouseDown[1] = FALSE
theMouseWasUp = TRUE
case myState of
TRUE:
mySprite.member = myOnMember
updateStage
do myOnCommand
FALSE:
mySprite.member = myOffMember
updateStage
do myOffCommand
end case
if ourGroupList.count() then
if myState then
call (#ToggleButton_Off, ourGroupList, me)
end if
end if
end Toggle
on CheckGroupForClick me -- sent by mouseUpOutside
groupRollover = call (#ToggleButton_Rollover, ourGroupList, [])
if not groupRollover.count() then
ourMouseDown[1] = FALSE
end if
end Disactivate
-- PUBLIC METHODS (responses to #sendSprite, #sendAllSprites, #call) --
on ToggleButton_GroupRollCall me, groupID, groupList
-- sent by each new button that joins the group
if groupID = ourID then
ourGroupList = groupList
ourGroupList.append(me)
end if
return groupList
end ToggleButton_GroupRollCall
on ToggleButton_MouseDownList me, mouseDownList
ourMouseDown = mouseDownList
end ToggleButton_MouseDownList
on ToggleButton_Rollover me, theList
if the rollover = me.spriteNum then
theList.append(me.spriteNum)
end if
return theList
end ToggleButton_Rollover
on ToggleButton_Off me, callingBehavior
-- sent when the member of the group which is toggled ON
if callingBehavior = me then exit
Toggle me, FALSE
end ToggleButton_Off
on ToggleButton_State me, groupID, statesList
if not voidP (groupID) then
if groupID <> ourID then exit
end if
case ilk (statesList) of
#void: return myState
#list:
statesList.append(myState)
#propList:
statesList.addProp(me.spriteNum, myState)
end case
return statesList
end ToggleButton_State
on ToggleButton_ActiveButton me, groupID, theList
if not voidP (groupID) then
if groupID <> ourID then exit
end if
if not listP (theList) then
theList = [:]
end if
if not theList.count() and myState then
theList.addProp (#sprite, me.spriteNum)
theList.addProp (#behavior, me)
end if
return theList
end ToggleButton_ActiveButton
on isOKToAttach (me, aSpriteType, aSpriteNum)
tIsOK = 0
if aSpriteType = #graphic then
tIsOK = 1
end if
return(tIsOK)
end on
-- AUTHOR-DEFINED PARAMETERS --
on getPropertyDescriptionList me
theMember = sprite(the currentSpriteNum).member
theMemberNum = theMember.number
return \
[ \
#myOffMember: \
[ \
#comment: "-OFF STATE- Standard member:", \
#format: #graphic, \
#default: theMember \
], \
#myOffOverMember: \
[ \
#comment: "Rollover member", \
#format: #graphic, \
#default: member (theMemberNum + 1) \
], \
#myOffDownMember: \
[ \
#comment: "MouseDown member", \
#format: #graphic, \
#default: member (theMemberNum + 2) \
], \
#myOnMember: \
[ \
#comment: "-ON STATE- Standard member", \
#format: #graphic, \
#default: member (theMemberNum + 3) \
], \
#myOnOverMember: \
[ \
#comment: "Rollover member", \
#format: #graphic, \
#default: member (theMemberNum + 4) \
], \
#myOnDownMember: \
[ \
#comment: "MouseDown member", \
#format: #graphic, \
#default: member (theMemberNum + 5) \
], \
#myOnCommand: \
[ \
#comment: "-COMMAND SENT- when switched ON", \
#format: #string, \
#default: "sendAllSprites #Toggle_On, the currentSpriteNum" \
], \
#myOffCommand: \
[ \
#comment: "when switched OFF", \
#format: #string, \
#default: "sendAllSprites #Toggle_Off, the currentSpriteNum" \
], \
#ourID: \
[ \
#comment: "ID string for the group", \
#format: #string, \
#default: EMPTY \
] \
]
end getPropertyDescriptionList